package com.anjoyo.xgh.musicshare.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.anjoyo.xgh.musicshare.R;
import com.anjoyo.xgh.musicshare.application.SongApplication;
import com.anjoyo.xgh.musicshare.entry.Song;

public class NetSongAdapter extends BaseAdapter {

	Context con;
	ArrayList<Song> songs = SongApplication.getInstance().songslist;
	LayoutInflater inflater;
	public int pos = -1;

	public NetSongAdapter(Context con) {
		this.con = con;
		inflater = LayoutInflater.from(con);
	}

	@Override
	public int getCount() {
		return songs.size();
	}

	@Override
	public Object getItem(int position) {
		return songs.get(position);
	}

	public Song getItemMuisc(int arg0) {
		return songs.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public void changeColor(int pos) {
		this.pos = pos;
		notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder h;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.netsong_item, null);
			h = new ViewHolder();
			h.pos = (TextView) convertView.findViewById(R.id.tv_num);
			h.namesinger = (TextView) convertView
					.findViewById(R.id.tv_songname);
			convertView.setTag(h);
		} else {
			h = (ViewHolder) convertView.getTag();
		}
		if (position == pos) {
			h.pos.setTextColor(Color.rgb(40, 194, 241));
			h.namesinger.setTextColor(Color.rgb(40, 194, 241));
		} else {
			h.pos.setTextColor(Color.BLACK);
			h.namesinger.setTextColor(Color.BLACK);
		}
		h.pos.setText((position + 1) + "");
		h.namesinger.setText(songs.get(position).getName() + "-"
				+ songs.get(position).getArtist());
		return convertView;
	}

	class ViewHolder {
		TextView pos, namesinger;
	}

}
